#include "asw/include/drv_api.h"
#include "asw/include/drv_io.h"
#include "asw/include/drv_tbl.h"
#include "asw/include/drv_field.h"

#undef DRV_DEF_M
#undef DRV_DEF_D
#undef DRV_DEF_F
#undef DRV_DEF_SDK_D
#undef DRV_DEF_SDK_F

#ifdef DRV_DEF_M
    #error DRV_DEF_M has been defined
#endif

#ifdef DRV_DEF_D
    #error DRV_DEF_D has been defined
#endif

#ifdef DRV_DEF_F
    #error DRV_DEF_F has been defined
#endif

#ifdef DRV_DEF_SDK_D
	#error DRV_DEF_SDK_D has been defined
#endif

#ifdef DRV_DEF_SDK_F
	#error DRV_DEF_SDK_F has been defined
#endif

#define CTC_DS_ADDR(ModuleName, InstNum, RegName, EntryOffset, OpType, TblType, EntryNum, DWord, ...) \
   const addrs_t RegName##_tbl_addrs_tma[InstNum] = {__VA_ARGS__};

#ifndef CTC_CLI_EN
 /*DS LIST*/
#define CTC_DS_INFO(ModuleName,InstNum,RegName, OpType,TblType, EntryNum, EntryOffset,DWord, ...) \
   { \
      EntryNum*InstNum, \
      DWord<<2, \
      OpType,     \
      InstNum, \
      sizeof(RegName##_tbl_fields)/sizeof(fields_t), \
      ModuleName##_id, \
      TblType,\
      EntryOffset,\
      RegName##_tbl_addrs_tma, \
      RegName##_tbl_fields, \
   },

  /*Field Info*/
#define CTC_FIELD_INFO(RegName, FieldName, Bits, ...) \
	{ \
	   RegName##_##FieldName##_f,\
	   Bits, \
	   __VA_ARGS__, \
	},
#else
 /*DS LIST*/
#define CTC_DS_INFO(ModuleName,InstNum,RegName, OpType,TblType, EntryNum, EntryOffset,DWord, ...) \
   { \
      #RegName, \
      EntryNum*InstNum, \
      DWord<<2, \
      OpType,     \
      InstNum, \
      sizeof(RegName##_tbl_fields)/sizeof(fields_t), \
      ModuleName##_id, \
      TblType,\
      EntryOffset,\
      RegName##_tbl_addrs_tma, \
      RegName##_tbl_fields, \
   },

  /*Field Info*/
#define CTC_FIELD_INFO(RegName, FieldName, Bits, ...) \
	{ \
     #FieldName, \
	   RegName##_##FieldName##_f,\
	   Bits, \
	   __VA_ARGS__, \
	},
#endif

#if 0
 /*Field Addr*/
#define CTC_FIELD_ADDR(RegName, FieldName, ...) \
  const segs_t RegName##_##FieldName##_tbl_segs[] = {__VA_ARGS__};
#endif

 /*DS Field List Seperator*/
#define CTC_DS_SEPERATOR_INFO(RegName) \
 }; \
 const fields_t RegName##_tbl_fields[] = {


#if 0
 /* Segment Info*/
#define DRV_DEF_M(ModuleName, InstNum)
#ifdef DRV_DS_LITE
#define DRV_DEF_D(ModuleName, InstNum, RegName, EntryOffset, OpType,TblType, EntryNum, DWord,...)
#define DRV_DEF_F(ModuleName, InstNum, RegName, FieldName, Bits, ...)
#else
#define DRV_DEF_D(ModuleName, InstNum, RegName, EntryOffset, OpType,TblType, EntryNum, DWord,...)
#define DRV_DEF_F(ModuleName, InstNum, RegName, FieldName, Bits, ...) \
        CTC_FIELD_ADDR(RegName, FieldName, __VA_ARGS__)
#endif
#define DRV_DEF_SDK_D(ModuleName, InstNum, RegName, EntryOffset, OpType,TblType, EntryNum, DWord,...)
#define DRV_DEF_SDK_F(ModuleName, InstNum, RegName, FieldName, Bits, ...) \
        CTC_FIELD_ADDR(RegName, FieldName, __VA_ARGS__)

#include "asw/include/drv_ds.h"
#undef DRV_DEF_M
#undef DRV_DEF_D
#undef DRV_DEF_F
#undef DRV_DEF_SDK_D
#undef DRV_DEF_SDK_F
#endif
 /* Field Info*/
#define DRV_DEF_M(ModuleName, InstNum)
#ifdef DRV_DS_LITE
#define DRV_DEF_D(ModuleName, InstNum, RegName, EntryOffset, OpType,TblType, EntryNum, DWord,...)
#define DRV_DEF_F(ModuleName, InstNum, RegName, FieldName, Bits, ...)
#else
#define DRV_DEF_D(ModuleName, InstNum, RegName, EntryOffset, OpType,TblType, EntryNum, DWord,...) \
        CTC_DS_SEPERATOR_INFO(RegName)
#define DRV_DEF_F(ModuleName, InstNum, RegName, FieldName, Bits, ...) \
        CTC_FIELD_INFO(RegName, FieldName, Bits, __VA_ARGS__)
#endif
#define DRV_DEF_SDK_D(ModuleName, InstNum, RegName, EntryOffset, OpType,TblType, EntryNum, DWord,...) \
        CTC_DS_SEPERATOR_INFO(RegName)
#define DRV_DEF_SDK_F(ModuleName, InstNum, RegName, FieldName, Bits, ...) \
        CTC_FIELD_INFO(RegName, FieldName, Bits, __VA_ARGS__)


#ifndef CTC_CLI_EN
fields_t fields_1st = {0,0,{0, 0},
#include "asw/include/drv_ds.h"
};
#else
 fields_t fields_1st = {NULL,0,0,{0, 0},
#include "asw/include/drv_ds.h"
 };
#endif
#undef DRV_DEF_M
#undef DRV_DEF_D
#undef DRV_DEF_F
#undef DRV_DEF_SDK_D
#undef DRV_DEF_SDK_F

 /* DS Address*/
#define DRV_DEF_M(ModuleName, InstNum)
#ifdef DRV_DS_LITE
#define DRV_DEF_D(ModuleName, InstNum, RegName, EntryOffset, OpType, TblType, EntryNum, DWord, ...)
#define DRV_DEF_F(ModuleName, InstNum, RegName, FieldName, FullName, Bits, ...)
#else
#define DRV_DEF_D(ModuleName, InstNum, RegName, EntryOffset, OpType, TblType, EntryNum, DWord, ...) \
        CTC_DS_ADDR(ModuleName, InstNum, RegName, EntryOffset, OpType, TblType, EntryNum, DWord, __VA_ARGS__)
#define DRV_DEF_F(ModuleName, InstNum, RegName, FieldName, FullName, Bits, ...)
#endif
#define DRV_DEF_SDK_D(ModuleName, InstNum, RegName, EntryOffset, OpType, TblType, EntryNum, DWord, ...) \
        CTC_DS_ADDR(ModuleName, InstNum, RegName, EntryOffset, OpType, TblType, EntryNum, DWord, __VA_ARGS__)
#define DRV_DEF_SDK_F(ModuleName, InstNum, RegName, FieldName, FullName, Bits, ...)

#include "asw/include/drv_ds.h"
#undef DRV_DEF_M
#undef DRV_DEF_D
#undef DRV_DEF_F
#undef DRV_DEF_SDK_D
#undef DRV_DEF_SDK_F

 /* DS List*/
#define DRV_DEF_M(ModuleName, InstNum)
#ifdef DRV_DS_LITE
#define DRV_DEF_D(ModuleName, InstNum, RegName, EntryOffset, OpType,TblType, EntryNum, DWord,...)
#define DRV_DEF_F(ModuleName, InstNum, RegName, FieldName, Bits, ...)
#else
#define DRV_DEF_D(ModuleName, InstNum, RegName, EntryOffset, OpType,TblType, EntryNum, DWord,...) \
        CTC_DS_INFO(ModuleName,InstNum,RegName,  OpType, TblType,EntryNum, EntryOffset,DWord, ...)
#define DRV_DEF_F(ModuleName, InstNum, RegName, FieldName, Bits, ...)
#endif
#define DRV_DEF_SDK_D(ModuleName, InstNum, RegName, EntryOffset, OpType,TblType, EntryNum, DWord,...) \
        CTC_DS_INFO(ModuleName,InstNum,RegName,  OpType, TblType,EntryNum, EntryOffset,DWord, ...)
#define DRV_DEF_SDK_F(ModuleName, InstNum, RegName, FieldName, Bits, ...)

const tables_info_t drv_tbls_list[] = {
#include "asw/include/drv_ds.h"
};

